﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
public partial class Admin_Leaveword_Dt : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //检查用户权限
        if (Session["Uid"] == null)
        {
            //无权限返回登录页
            Response.Redirect("AD_Login.aspx");
            return;
        }
     
      

        if (!IsPostBack)
        {
            //提取URL传参
            string ID = Request.QueryString["ID"].ToString();
            if (ID!="")
            {
                lblMesage.Text = "";
                Bind_Txt(ID);}
                
            
        }
    }
    private void Bind_Txt(string ID)
    {
        //定义sql语句
        string sql = "select * from Leaveword_Info where leaID=@leaID";
        //定义参数
        SqlParameter[] para = { new SqlParameter("@leaID", SqlDbType.Int) };
        //参数赋值
        para[0].Value = ID;
        //取得数据
        SqlDataReader DR = DataAccess.GetReader(sql, para);
        if (DR.HasRows)
        {//如果有数据
            while (DR.Read())
            {//显示数据
                ViewState["ID"] = ID;
                lbName.Text = DR["leaName"].ToString();
                lblID.Text = ID;
                lbTitle.Text = DR["leaTitle"].ToString();
                lbContent.Text = DR["leaContent"].ToString();
                if (  Convert.ToBoolean(DR["leaIsShow"]))
                cbISshow.Checked = true; 
                else
                    cbISshow.Checked = false;
                txtReply.Text = DR["leaReply"].ToString();

            }
        }
    }
    protected void btnOK_Click(object sender, EventArgs e)
    {
        string sql = "update Leaveword_Info set leaReply=@leaReply,leaIsShow=@leaIsShow,leaReplyTime=@leaReplyTime where leaID=@leaID";
        //定义参数
        SqlParameter[] para = {
                    new SqlParameter("@leaReply", SqlDbType.NText),
                     new SqlParameter("@leaIsShow", SqlDbType.Bit),
                              new SqlParameter("@leaID",SqlDbType.Int),
                              new SqlParameter("@leaReplyTime",SqlDbType.DateTime)};
        para[0].Value = txtReply.Text;
        if (cbISshow.Checked)
        {
            para[1].Value = 1;
        }
        else
        {
            para[1].Value = 0;
        }
        para[2].Value = lblID.Text;
        para[3].Value = System.DateTime.Now;
        if (DataAccess.ExecuteSQL(sql, para))
        {
            lblMesage.Text = "修改成功";
        }
        else
        {
            lblMesage.Text = "修改失败";
        }
    }



    protected void btBc_Click(object sender, EventArgs e)
    {
        Response.Redirect("Leaveword_Manage.aspx");
    }
}